﻿using System;
using System.IO.Packaging;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Xps.Packaging;

namespace GEPL.Views
{
    /// <summary>
    /// Interaction logic for HelpWindow.xaml
    /// </summary>
    public partial class HelpWindow : Window
    {
        public HelpWindow()
        {
            InitializeComponent();

            // check the UI language (current thread culture)
            var currentCulture = Thread.CurrentThread.CurrentCulture;
            var langs = new string[] { "pl", "en" };
            if (!langs.Contains(currentCulture.TwoLetterISOLanguageName))
                return;

            // get proper XPS file from resources
            var uri = new Uri(String.Format("pack://application:,,,/manuals/User_manual_{0}.xps", currentCulture.TwoLetterISOLanguageName));
            var package = PackageStore.GetPackage(uri);
            if (package == null)
            {
                var stream = Application.GetResourceStream(uri).Stream;
                package = Package.Open(stream);
                PackageStore.AddPackage(uri, package);
            }

            // load the XPS file into the DocumentViewer control
            var xpsDoc = new XpsDocument(package, CompressionOption.Maximum, uri.AbsoluteUri);
            var fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
            DocViewer.Document = fixedDocumentSequence;
            xpsDoc.Close();
        }
    }
}